<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
             label-width="80px">
      <el-form-item label="入库单号" prop="nos">
        <el-input v-model="queryParams.nos" placeholder="请输入批次编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="到货单号" prop="daohuoNos">
        <el-input v-model="queryParams.daohuoNos" placeholder="请输入批次编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="采购人" prop="lvBuycreateUsername">
        <el-input v-model="queryParams.lvBuycreateUsername" placeholder="请输入采购人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="制单人" prop="createBy">
        <el-input v-model="queryParams.createBy" placeholder="请输入制单人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="质检人" prop="zhijianName">
        <el-input v-model="queryParams.zhijianName" placeholder="请输入质检人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="收货人" prop="shourenName">
        <el-input v-model="queryParams.shourenName" placeholder="请输入收货人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="供应商" prop="supplierName">
        <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="入库人" prop="rukupeople">
        <el-input v-model="queryParams.rukupeople" placeholder="请输入入库人"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="入库日期" prop="rukuDate">
        <el-date-picker clearable v-model="queryParams.rukuDate"
                        type="date" value-format="yyyy-MM-dd" placeholder="请选择入库日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
              :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="入库单号" align="center" prop="nos" width="150" show-overflow-tooltip/>
      <el-table-column label="到货单号" align="center" prop="daohuoNos" width="150"/>

      <el-table-column label="采购类型" align="center" prop="source">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.caigou_type" :value="scope.row.params.lvBuyYwType"/>
        </template>
      </el-table-column>

      <el-table-column label="入库来源" align="center" prop="source">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.ruku_source" :value="scope.row.source"/>
        </template>
      </el-table-column>
      <el-table-column label="出库/入库" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.churuku_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column sortable label="采购人" align="center" prop="params.lvBuycreateUsername"/>
      <el-table-column sortable label="制单人" align="center" prop="createBy"/>
      <el-table-column sortable label="质检人" align="center" prop="params.zhijianName"/>
      <el-table-column sortable label="收货人" align="center" prop="params.shourenName"/>
      <el-table-column label="供应商名称" align="center" prop="supplierName"/>
      <el-table-column label="出/入库人" align="center" prop="rukupeople"/>
      <el-table-column label="出/入库日期" align="center" prop="rukuDate" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rukuDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>>
      <el-table-column label="出/入库状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.storage_state" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>

      <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="showDetail(scope.row)">查看明细</el-button>
          <el-button v-show="scope.row.params.lvBuyYwType ==='666' && scope.row.outFlag ==='0'" size="mini" type="text" icon="el-icon-magic-stick" @click="oneKeyOut(scope.row)">一键出库</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

    <showDetail-form ref="showDetailForm" @ok="getList"></showDetail-form>
  </div>
</template>

<script>
import {deleteAction, downloadFile, getAction} from '@/api/manage'
import ShowDetailForm from '@/views/develop/lvRuku/module/ShowDetailForm'

export default {
  name: "LvRukuBuyList",
  dicts: ['churuku_type', 'caigou_type', 'storage_state','ruku_source'],
  components: {
    ShowDetailForm,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 入库单表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        mainId: null,
        nos: null,
        ddDate: null,
        subDate: null,
        type: null,
        ywType: null,
        source: null,
        customerId: null,
        customerName: null,
        isBuy: null,
        supplierId: null,
        supplierName: null,
        deptId: null,
        deptName: null,
        userId: null,
        userName: null,
        state: null,
        rukupeople: null,
        rukuid: null,
        rukuDate: null,
        status: null,
        lvBuycreateUsername: null,
        createBy: null,
        zhijianName: null,
        shourenName: null,
      },
      url: {
        list: '/lvRuku/lvRuku/list',
        remove: '/lvRuku/lvRuku/',
        export: '/lvRuku/lvRuku/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.queryParams.source = this.$route.query.source;
    this.queryParams.type = this.$route.query.type;
    this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
    showDetail(row) {
      this.$refs.showDetailForm.show(row);
    },
    /** 查询入库单列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },

    oneKeyOut(row){
      let that = this;
      that.loading = false;
      that.$confirm('是否确认一键出库?', "确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        getAction('/lvRuku/lvRuku/oneKeyBuyOut/'+row.id, {}).then(response => {
          that.$modal.msgSuccess("一键出库成功");
          that.getList();
        })
      });


    }




  }
};
</script>
